import { ApiCall } from "tsrpc";
import { ReqGetAddress, ResGetAddress } from "../../shared/protocols/pandian/PtlGetAddress";
import { Global } from "../../models/Global";


export default async function (call: ApiCall<ReqGetAddress, ResGetAddress>) {
    const searchParam = call.req.SerialNum; // 假设请求的参数字段名为 ScanNum
// 使用聚合管道来获取按时间排序后的最新文档
let op = await Global.db.collection("pandian")
    .find({ $or: [{ AssetNum: searchParam }, { SerialNum: searchParam }] })
    .sort({ time: -1 }) // -1 表示降序排列，最新的时间会在最前面
    .limit(1) // 限制结果只返回一个文档
    .toArray(); // 将结果转换为数组
    if (op) {
        call.succ({
            
            Location: op[0].Location
        });
    } else {
        call.succ({
            Location: ""
        });
    }
    
}
